package cn.itcast.com.Object.hashcode;

import java.util.Objects;

/*
 public int hashcode()
 返回该对象的哈希码值，为了提高哈希表的性能
 对象.hashcode()
 */
public class demo1 {
    public static void main(String[] args) {
        int i = 100;
        double j = 1.2;
        Hashclass hashclass = new Hashclass(i,j);
        Hashclass hashclass1 = new Hashclass(i,j);
        System.out.println(hashclass.hashCode());
        System.out.println(hashclass1.hashCode());
    }
}
class Hashclass{
    int i;
    double j;

    public Hashclass(int i, double j) {
        this.i = i;
        this.j = j;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Hashclass hashclass = (Hashclass) o;
        return i == hashclass.i &&
                Double.compare(hashclass.j, j) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(i, j);
    }
}
